package _21_多线程._1114_按序打印;

import java.util.concurrent.atomic.AtomicInteger;

public class _1114_按序打印_volatile {

    private volatile int num = 0;

    public _1114_按序打印_volatile() {

    }

    public void first(Runnable printFirst) throws InterruptedException {
        printFirst.run();
        num = 1;
    }

    public void second(Runnable printSecond) throws InterruptedException {
        while (num != 1);
        // printSecond.run() outputs "second". Do not change or remove this line.
        printSecond.run();
        num = 2;
    }

    public void third(Runnable printThird) throws InterruptedException {
        while (num != 2);
        // printSecond.run() outputs "second". Do not change or remove this line.
        printThird.run();
    }

}
